package com.ludomancy.playground.items;

import java.awt.Graphics;
import java.awt.Point;

import com.ludomancy.gamelib.ImageAnimation;
import com.ludomancy.gamelib.ImageStrip;
import com.ludomancy.gamelib.ResourceManager;
import com.ludomancy.gamelib.Sound;
import com.ludomancy.playground.Component;
import com.ludomancy.playground.Game;

public class Recycler extends Component
{
	private ImageAnimation recycler;
	private ImageAnimation bubble;
	private boolean isSick = false;
	
	public Recycler(Point pos)
	{
		super(pos.x,pos.y);
		if(recycler == null)
		{
			recycler = new ImageAnimation(new ImageStrip(ResourceManager.getImage("recycler.png"), 72, 84), 4);
			bubble = new ImageAnimation(new ImageStrip(ResourceManager.getImage("lava.png"), 20, 29), 4);
		}
		recycler.looping = true;
		recycler.play();
	}
	
	public int getWidth()
	{
		return 72;
	}
	
	public int getHeight()
	{
		return 84;
	}
	
	public boolean isMovable()
	{
		return false;
	}

	public void paint(Graphics g, int px, int py)
	{
		recycler.paintCurrentFrame(g, px, py);
		bubble.paintCurrentFrame(g, px + 24 , pos.y + 20);
	}
	
	public void onCollided(Component other)
	{
		if(other instanceof Egg && !((Egg)other).isEmpty)
		{
			return;
		}
		
		process(other);
	}
	
	private void process(Component other)
	{
		Sound.play("bubble.wav");
		Game.game.world.remove(other);
		if(!isSick)
		{
			// produce metal!
			if(other.isMadeOfMetal())
			{
			}
//			if(other instanceof Egg)
//			{
//				isSick = true;
//				recycler = new ImageAnimation(new ImageStrip(ResourceManager.getImage("recycler_sick.png"), 72, 84), 4);
//				bubble = new ImageAnimation(new ImageStrip(ResourceManager.getImage("swamp.png"), 20, 29), 4);
//			}
		}
		bubble.rewind();
		bubble.play();
	}

	public void update()
	{
		recycler.update();
		bubble.update();
	}
}
